<template>
  <view class="content">
    <template v-for="(parentMessage, baseListIndex) in parentMessageList">
      <view
        class="parentMessage"
        v-if="(baseListIndex == 1 && flag == 1) || baseListIndex != 1"
      >
        <view class="shopName" v-if="parentMessage.shopName">
          <text>{{ parentMessage.shopName }}</text>
        </view>
        <view class="parent-view">
          <template v-for="(item, index) in parentMessage.baseList">
            <view
              class="child-view"
              :index="index"
              @click="clickHandle(item)"
              v-if="
                (item.channelName != '我的优惠券' && flag == 1) ||
                item.channelName == '我的优惠券'
              "
            >
              <image
                :src="item.channelLogo"
                class="image"
                mode="aspectFill"
                style="border-radius: 30rpx; height: 110rpx; width: 130rpx"
              />
              <text class="text">{{ item.channelName }}</text>
            </view>
          </template>
        </view>
      </view>
    </template>
  </view>
</template>

<script>
import { toast } from "@/utils/common";
// #ifdef H5

// #endif
// import openApp from '@/utils/openApp'
import parame from "@/utils/mobile.js";
import AppOpener from "@/utils/openApp";
const mobile = parame.parame;
const app = getApp();
export default {
  name: "home",
  props: {
    parentMessageList: {
      type: Array,
      required: true,
    },
    flag: {
      type: Number || String,
      required: true,
    },
  },
  data() {
    return {
      show: false,
      title: "WIFI信息",
      content: "名称: WIF名称\n密码: WIFI密码",
      wifiName: "",
      wifiPass: "",
      parentMessageList1: [
        {
          shopName: "ce",
          baseList: [
            {
              name: "photo",
              title: "发抖音",
            },
            {
              name: "lock",
              title: "锁头",
            },
          ],
        },
      ],
      timeOut: null,
    };
  },
  methods: {
    async clickHandle(item) {
      // #ifdef MP-WEIXIN
      const token = this.$store.state.user.token;
      // if (!token) {
      //   app.navigationTo("page_user/login/login");
      //   return false;
      // }
      // #endif

      if (item.url) {
        app.navigationTo(item.url);
        return false;
      }

      if (item.path_scheme && item.channelType == 3) {
        uni.showLoading({
          title: "正在唤起应用",
          mask: true,
        });
        const ios_store = mobile.ios[item.type];
        const android_store = mobile.android[item.type];
        // const AppRouter = new AppOpener({
        //   scheme: item.path_scheme,
        //   ios: ios_store,
        //   package: android_store,
        // });
        // AppRouter.open(
        //   () => {
        //     uni.hideLoading();
        //   },
        //   () => {
        //     uni.hideLoading();
        //   }
        // );
        const router = new AppOpener({
          scheme: item.path_scheme,
          ios: ios_store,
          package: android_store,
        });
        try {
          await router.open();
          uni.hideLoading();
        } catch (error) {
          uni.hideLoading();
          console.log("打开失败:", error);
        }
        return false;
      }
      if ((item.channelType == 1) & (item.channelId != 10)) {
        let type =
          item.channelId == 1
            ? "抖音"
            : item.channelId == 2
            ? "快手"
            : "小红书";
        app.navigationTo(`pages/H5/material-video?type=${type}`);
        return false;
      }
      if (item.channelType == 2 || item.channelId == 10) {
        let type =
          item.channelId == 4
            ? "meituan"
            : item.channelId == 5
            ? "dianping"
            : item.channelId == 6
            ? "gaode"
            : "weixin";
        app.navigationTo(`pages/H5/material?type=${type}`);
        return false;
      }
      toast("敬请期待");
    },
  },
};
</script>

<style lang="scss">
.content {
  display: flex;
  flex-direction: column;
  height: auto;
  width: 100%;
  border-radius: 20rpx;

  .parentMessage {
    padding: 28rpx 20rpx;
    margin: 10rpx 0;
    background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.62) 64%,
      #ffffff 100%
    );
    box-shadow: 0rpx 0rpx 40rpx 0rpx rgba(0, 0, 0, 0.04);
    border: 2rpx solid #ffffff;
    border-radius: 20rpx;
    position: relative;
  }

  .shopName {
    width: 100%;
    font-size: 30rpx;
    font-weight: 500;
    margin-bottom: 48rpx;
  }

  .grid-item-box {
    position: absolute;
    left: 0;
    right: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    height: 162rpx;
    margin-left: 0rpx;
    margin-right: 0rpx;
    // width: 100%;
    width: 130rpx;
    align-items: center;
    justify-content: center;
    border-radius: 20rpx;

    // border: 3rpx solid red;
    // image {
    // 	height: 110rpx;
    // 	width: 128px;
    // }
    .imageView {
      // border: 3rpx solid red;
      height: 110rpx;
      width: 130rpx;
      border-radius: 20rpx;
      overflow: hidden;
    }

    .text {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 66rpx;
      width: 100%;
      font-family: Source Han Sans, Source Han Sans;
      font-weight: 500;
      font-size: 24rpx;
      line-height: 44rpx;
      font-style: normal;
      color: #000000;
    }
  }

  .parent-view {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    padding: 0 15rpx;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 40rpx;
    border-radius: 20rpx;
  }

  .child-view {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    height: 162rpx;
    // width: 100%;
    width: 130rpx;
    align-items: center;
    justify-content: center;
    border-radius: 20rpx;
    // width: calc(25% -10px);
    box-sizing: border-box;
    // border: 3rpx solid red;
    background-color: initial;

    // padding: 10rpx;
  }

  .text {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 66rpx;
    width: 100%;
    font-family: Source Han Sans, Source Han Sans;
    font-weight: 500;
    font-size: 24rpx;
    line-height: 44rpx;
    font-style: normal;
    color: #000000;
    margin-top: 10rpx;
  }
}
</style>
